"""
@author: 江同学呀
@file: base_string_field.py
@date: 2023/8/22 19:45
@desc:
"""


from abc import ABC
from typing import Type, Union, Dict, Optional

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField


class _BaseStringField(_BaseField, ABC):
    """
    字符串类型字段基类
    """

    def __init__(self, field_name: str = None, value: str = None, default: str = None, *args, **kwargs):
        super(_BaseStringField, self).__init__(field_name=field_name, value=value, default=default, *args, **kwargs)
        self._parent_field: Optional[_BaseStringField] = None
        return

    def __get__(self, instance: _Base, owner: Type["_BaseStringField"]) -> Union["_BaseStringField", str]:
        return super(_BaseStringField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: str):
        super(_BaseStringField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> str:
        return self._value

    @value.setter
    def value(self, value: str):
        self._value: str = value
        return

    def _build(self) -> Dict:
        raise NotImplementedError

    def _set_parent_field(self, field: "_BaseField") -> "_BaseStringField":
        """
        设置字段对象
        :param field:
        :return:
        """
        self._parent_field: _BaseField = field
        # self._field_name_path: str = self._parent_field._field_name + "." + self._field_name
        return self






